<template>
    <div
        class="dialogContent"
        style="margin-top: 20px;width: 960px;"
    >
        <el-form
            ref="templateFormRef"
            :model="drawingForm"
            label-width="88px"
            class="demo-ruleForm"
            :inline="true"
        >
            <div class="dialogModel">
                <el-row>
                    <el-col :span="8">
                        <el-form-item
                            label="仪器"
                            prop="title"
                            style="width: 100%;"
                        >
                            <el-select
                                v-model="drawingForm.instrument"
                                class="m-2"
                                placeholder="请选择仪器"
                            >
                                <el-option
                                    v-for="m in instruments"
                                    :key="m.valueName"
                                    :label="m.valueName"
                                    :value="m.valueName"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="方法"
                            prop="title"
                            style="width: 100%;"
                        >
                            <el-select
                                v-model="drawingForm.method"
                                class="m-2"
                                placeholder="请选择方法"
                            >
                                <el-option
                                    v-for="m in methodNames"
                                    :key="m.valueName"
                                    :label="m.valueName"
                                    :value="m.valueName"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="环境"
                            prop="title"
                            style="width: 100%;"
                        >
                            <el-input
                                v-model="drawingForm.temperature"
                                placeholder="温度°C"
                                style="width: 76px;margin-right: 4px;"
                            />
                            <span style="margin-right: 16px;">°C</span>
                            <el-input
                                v-model="drawingForm.humidity"
                                placeholder="湿度%"
                                style="width: 76px;margin-right: 4px;"
                            />
                            <span>%</span>
                        </el-form-item>
                    </el-col>

                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item
                            label="波长"
                            prop="wavelength"
                            style="width: 100%;"
                        >
                            <el-input
                                v-model="drawingForm.wavelength"
                                placeholder="220nm/275nm"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="比色皿"
                            prop="beaker"
                            style="width: 100%;"
                        >
                            <el-input
                                v-model="drawingForm.beaker"
                                placeholder="请输入"
                                style="width: 85%;margin-right: 10px;"
                            />
                            <span>cm</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="标液浓度"
                            prop="solutionConcent"
                            style="width: 100%;"
                        >
                            <div style="display: flex;flex-direction: row;align-items: center;">
                                <el-input
                                    v-model="drawingForm.solutionConcent"
                                    placeholder="请输入"
                                />

                                <el-select
                                    v-model="drawingForm.solutionConcentUnit"
                                    class="m-2"
                                    placeholder="请选择"
                                    style="width: 140px"
                                >
                                    <el-option
                                        v-for="m in units"
                                        :key="m.valueName"
                                        :label="m.valueName"
                                        :value="m.valueName"
                                    />
                                </el-select>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item
                            label="A0"
                            prop="blankA220"
                            style="width: 100%;"
                        >
                            <el-input
                                v-model="drawingForm.blankA220"
                                type="number"
                                placeholder="空白吸光值A220"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item
                            label=""
                            prop="blankA275"
                            style="width: 100%;margin-left: 10px;"
                        >
                            <el-input
                                v-model="drawingForm.blankA275"
                                placeholder="空白吸光值A275"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="A220-2*A275"
                            prop="blankAresult"
                            label-width="180px"
                            style="width: 100%;margin-left: 20px;"
                        >
                            <el-input
                                v-model="drawingForm.blankAresult"
                                placeholder="空白吸光值A220-2*A275"
                                disabled
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
            </div>

            <div class="dialogModel">
                <div class="modelTitle">
                    <div>曲线绘制</div>
                    <div class="loactionResultEdit">
                        <el-button
                            type="primary"
                            size="small"
                            :icon="Histogram"
                            @click="addCurve"
                        >
                            生成曲线
                        </el-button>
                    </div>
                </div>
                <el-row>
                    <el-col
                        :span="1"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">取样体积(ml)</div>
                    </el-col>
                    <el-col
                        :span="4"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">总氮含量(ug)</div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">吸光值(A220)</div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">吸光值(A275)</div>
                    </el-col>
                    <el-col
                        :span="4"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">吸光值(A220-2A275)</div>
                    </el-col>
                    <el-col
                        :span="4"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">减除空白后吸光度(A)</div>
                    </el-col>
                    <el-col
                        :span="1"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                        </div>
                    </el-col>
                </el-row>
                <el-row
                    v-for="(item, index) in drawingForm.pointsArray"
                    :key="index"
                >
                    <el-col
                        :span="1"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.sampleVolume"
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="4"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.multiplyValue"
                                type="number"
                                disabled
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.a220"
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.a275"
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="4"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.minusValue"
                                disabled
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="4"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.emptyValue"
                                disabled
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">

                            <div
                                class="operateIcon"
                                style="width: 80px;"
                            >
                                <img
                                    src="@/assets/images/plus.png"
                                    alt=""
                                    @click="addPoints"
                                    style=" width: 20px;height: 20px;margin-right: 4px;margin-top: 5px"
                                >
                                <img
                                    v-if="drawingForm.pointsArray.length > 1"
                                    src="@/assets/images/minus.png"
                                    alt=""
                                    @click="deletePoints(index)"
                                    style=" width: 20px;height: 20px;margin-right: 4px;margin-top: 5px"
                                >
                            </div>
                        </div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <!-- <chart-line-bar
                            :chartData="chartDataList"
                            xAxisName="multiplyValue"
                            :option="option"
                            :chartType="chartType"
                            :twoYAxis="false"
                            :orient="'horizontal'"
                        ></chart-line-bar> -->
                        <chart-scatter
                            :chartData="chartDataList"
                            v-if="chartDataList.length > 0"
                        >
                        </chart-scatter>
                    </el-col>
                </el-row>
                <el-row v-if="chartDataList.length > 0">
                    <el-col :span="24">
                        <div style="text-align: center;">拟合方程：{{ drawingForm.expression }} (r={{ drawingForm.rsquared }})</div>
                    </el-col>
                </el-row>
            </div>
            <div class="dialogModel">
                <div class="modelTitle">
                    <div>回测验证</div>
                    <div class="loactionResultEdit">
                        <el-button
                            type="primary"
                            size="small"
                            :icon="Switch"
                            @click="handleResult"
                        >
                            计算
                        </el-button>
                    </div>
                </div>

                <el-row>
                    <el-col :span="7">
                        <el-form-item
                            label="样品标准值(mg/L)"
                            label-width="140"
                            prop="standardConcentration"
                            style="width: 100%;margin-left: 10px;"
                        >
                            <el-input
                                v-model="drawingForm.standardConcentration"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item
                            label="±"
                            label-width="30"
                            prop="standardConcentrationExtra"
                            style="width: 100%;margin-left: 10px;"
                        >
                            <el-input
                                v-model="drawingForm.standardConcentrationExtra"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="6">
                        <el-form-item
                            label="A0"
                            prop="backtestingblankA220"
                            style="width: 100%;"
                        >
                            <el-input
                                v-model="drawingForm.backtestingblankA220"
                                type="number"
                                placeholder="空白吸光值A220"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item
                            label=""
                            prop="backtestingblankA275"
                            style="width: 100%;margin-left: 10px;"
                        >
                            <el-input
                                v-model="drawingForm.backtestingblankA275"
                                placeholder="空白吸光值A275"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="9">
                        <el-form-item
                            label="A220-2*A275"
                            label-width="190px"
                            prop="backtestingblankAresult"
                            style="width: 100%;margin-left: 20px;"
                        >
                            <el-input
                                v-model="drawingForm.backtestingblankAresult"
                                placeholder="空白吸光值A220-2A275"
                                disabled
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">样品编号</div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">取样体积(ml)</div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">A220</div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">A275</div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">A220-2A275</div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">减除空白后吸光度(A)</div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">测定值(ug)</div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">浓度(mg/L)</div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content el-col-content-th">平均值(mg/L)</div>
                    </el-col>
                    <el-col
                        :span="1"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                        </div>
                    </el-col>
                </el-row>
                <el-row
                    v-for="(item, index) in drawingForm.samplePointsArray"
                    :key="index"
                >
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input v-model="item.sampleNumber" />
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.sampleVolume"
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.a220"
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.a275"
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.minusValue"
                                type="number"
                                disabled
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.emptyValue"
                                disabled
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.testValue"
                                disabled
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="2"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">
                            <el-input
                                v-model="item.concentrationValue"
                                disabled
                                type="number"
                            />
                        </div>
                    </el-col>
                    <el-col
                        :span="3"
                        style="padding: 0 2px;"
                    >
                        <div
                            class="el-col-content"
                            v-show="index == 0"
                        >
                            <p
                                class="averageValue"
                                style="text-align: center;"
                                :style="{top:  drawingForm.samplePointsArray.length * 34 / 2  - 14+ 'px' }"
                            >{{ drawingForm.concentrationAverage }}</p>
                        </div>
                    </el-col>
                    <el-col
                        :span="1"
                        style="padding: 0 2px;"
                    >
                        <div class="el-col-content">

                            <div
                                class="operateIcon"
                                style="width: 80px;"
                            >
                                <img
                                    src="@/assets/images/plus.png"
                                    alt=""
                                    @click="addSamplePoints"
                                    style=" width: 20px;height: 20px;margin-right: 4px;margin-top: 5px"
                                >
                                <img
                                    v-if="drawingForm.samplePointsArray.length > 1"
                                    src="@/assets/images/minus.png"
                                    alt=""
                                    @click="deleteSamplePoints(index)"
                                    style=" width: 20px;height: 20px;margin-right: 4px;margin-top: 5px"
                                >
                            </div>
                        </div>
                    </el-col>
                </el-row>
                <el-row style="margin-top: 20px;">
                    <el-col :span="8">
                        <el-form-item
                            label="曲线编号"
                            prop="lineName"
                            style="width: 100%;"
                        >
                            <el-input
                                v-model="drawingForm.lineName"
                                placeholder="测定项目名称+YYMMDD"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item
                            label="曲线合格"
                            prop="isQualified"
                            style="width: 100%;margin-left: 10px;"
                        >
                            <el-radio-group v-model="drawingForm.isQualified">
                                <el-radio :value="1">是</el-radio>
                                <el-radio :value="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
            </div>
        </el-form>
    </div>
</template>
<script setup>
import taskHttp from "@/https/task.js";
import {
    Histogram,
    Switch
} from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import { defineEmits, defineExpose, defineProps, onMounted, ref, watch } from 'vue';
import ChartScatter from "./ChartScatter.vue";
const emits = defineEmits(["linearEquationFn"]);

const props = defineProps({
    lineCategory: {
        type: String,
        default: '',
    },
    lineCategoryName: {
        type: String,
        default: "",
    },
    handleType: {
        type: String,
        default: "",
    },
    handleRowDetail: {
        type: Object,
        default: {},
    },
});

let chartDataList = ref([]);
const option = ref({});
const chartType = ref([
    {
        type: "line",
        code: "yAxisValue",
        name: "线",
        linerColor: ["#58be3f", "#58be3f"],
    },
    {
        type: "scatter",
        code: "",
        name: "点",
        linerColor: ["#f56c6c", "#f56c6c"],
    },
]);
const drawingForm = ref({
    lineCategory: '1',
    lineCategoryName: 'NH₃-N曲线',
    instrument: '',
    temperature: '',
    humidity: '',
    method: '',
    solutionConcentUnit: '',
    wavelength: '220nm/275nm',
    beaker: '',
    solutionConcent: '',
    blankA220: '',
    blankA275: '',
    blankAresult: '',
    backtestingblankA220: '',
    backtestingblankA275: '',
    backtestingblankAresult: '',
    points: '',
    concentrationAverage: '',
    pointsArray: [
        {
            sampleNumber: '',
            sampleVolume: '0.00',
            multiplyValue: '',
            a275: '',
            a220: '',
            minusValue: '',
            emptyValue: '',
            yAxisValue: '',
        },
        {
            sampleNumber: '',
            sampleVolume: '0.20',
            multiplyValue: '',
            a275: '',
            a220: '',
            minusValue: '',
            emptyValue: '',
            yAxisValue: '',
        },
        {
            sampleNumber: '',
            sampleVolume: '0.50',
            multiplyValue: '',
            a275: '',
            a220: '',
            minusValue: '',
            emptyValue: '',
            yAxisValue: '',
        },
        {
            sampleNumber: '',
            sampleVolume: '1.00',
            multiplyValue: '',
            a275: '',
            a220: '',
            minusValue: '',
            emptyValue: '',
            yAxisValue: '',
        },
        {
            sampleNumber: '',
            sampleVolume: '3.00',
            multiplyValue: '',
            a275: '',
            a220: '',
            minusValue: '',
            emptyValue: '',
            yAxisValue: '',
        },
        {
            sampleNumber: '',
            sampleVolume: '5.00',
            multiplyValue: '',
            a275: '',
            a220: '',
            minusValue: '',
            emptyValue: '',
            yAxisValue: '',
        },
        {
            sampleNumber: '',
            sampleVolume: '7.00',
            multiplyValue: '',
            a275: '',
            a220: '',
            minusValue: '',
            emptyValue: '',
            yAxisValue: '',
        },
    ],
    samplePoints: '',
    samplePointsArray: [
        {
            sampleNumber: '',
            sampleVolume: '',
            a220: '',
            a275: '',
            minusValue: '',
            emptyValue: '',
            testValue: '',
            concentrationValue: '',
            averageValue: '',
        },
        {
            sampleNumber: '',
            sampleVolume: '',
            a220: '',
            a275: '',
            minusValue: '',
            emptyValue: '',
            testValue: '',
            concentrationValue: '',
            averageValue: '',
        },
    ],
    standardConcentration: '',
    standardConcentrationExtra: '',
    expression: '',
    intercept: '',
    rsquared: '',
    slope: '',
    isQualified: 0,
})
const initDate = () => {
    if (props.handleType == 'add') {
        chartDataList.value = []
        drawingForm.value = JSON.parse(JSON.stringify(props.handleRowDetail))
        drawingForm.value.wavelength = '220nm/275nm'
        drawingForm.value.pointsArray = [
            {
                sampleNumber: '',
                sampleVolume: '0.00',
                multiplyValue: '',
                a275: '',
                a220: '',
                minusValue: '',
                emptyValue: '',
                yAxisValue: '',
            },
            {
                sampleNumber: '',
                sampleVolume: '0.20',
                multiplyValue: '',
                a275: '',
                a220: '',
                minusValue: '',
                emptyValue: '',
                yAxisValue: '',
            },
            {
                sampleNumber: '',
                sampleVolume: '0.50',
                multiplyValue: '',
                a275: '',
                a220: '',
                minusValue: '',
                emptyValue: '',
                yAxisValue: '',
            },
            {
                sampleNumber: '',
                sampleVolume: '1.00',
                multiplyValue: '',
                a275: '',
                a220: '',
                minusValue: '',
                emptyValue: '',
                yAxisValue: '',
            },
            {
                sampleNumber: '',
                sampleVolume: '3.00',
                multiplyValue: '',
                a275: '',
                a220: '',
                minusValue: '',
                emptyValue: '',
                yAxisValue: '',
            },
            {
                sampleNumber: '',
                sampleVolume: '5.00',
                multiplyValue: '',
                a275: '',
                a220: '',
                minusValue: '',
                emptyValue: '',
                yAxisValue: '',
            },
            {
                sampleNumber: '',
                sampleVolume: '7.00',
                multiplyValue: '',
                a275: '',
                a220: '',
                minusValue: '',
                emptyValue: '',
                yAxisValue: '',
            }
        ]
    } else if (props.handleType == 'edit' || props.handleType == 'detail') {
        chartDataList.value = []
        drawingForm.value = JSON.parse(JSON.stringify(props.handleRowDetail))
        drawingForm.value.pointsArray = JSON.parse(drawingForm.value.points)
        drawingForm.value.samplePointsArray = JSON.parse(drawingForm.value.samplePoints)
        drawingForm.value.blankAresult = (drawingForm.value.blankA220 - 2 * drawingForm.value.blankA275).toFixed(3)
        chartDataList.value = drawingForm.value.pointsArray
    }
}

console.log(drawingForm.value, 'drawingForm.value')
const addPoints = () => {
    drawingForm.value.pointsArray.push({
        sampleVolume: '',
        multiplyValue: '',
        a275: '',
        a220: '',
        minusValue: '',
        emptyValue: '',
        yAxisValue: '',
    })
}
const deletePoints = (index) => {
    drawingForm.value.pointsArray.splice(index, 1)
}
const addSamplePoints = () => {
    drawingForm.value.samplePointsArray.push({
        sampleNumber: '',
        sampleVolume: '',
        a220: '',
        a275: '',
        minusValue: '',
        emptyValue: '',
        testValue: '',
        concentrationValue: '',
    })
}
const deleteSamplePoints = (index) => {
    drawingForm.value.samplePointsArray.splice(index, 1)
}

const addCurve = async () => {
    if (!drawingForm.value.solutionConcent) {
        ElMessage({
            type: 'warning',
            message: '请填写标液浓度！'
        })
        return
    }
    drawingForm.value.pointsArray.forEach(item => {
        item.multiplyValue = (item.sampleVolume * drawingForm.value.solutionConcent).toFixed(3)
        item.minusValue = (item.a220 - item.a275).toFixed(3)
        item.emptyValue = (item.minusValue - drawingForm.value.blankAresult).toFixed(3)
    })
    drawingForm.value.points = JSON.stringify(drawingForm.value.pointsArray)
    drawingForm.value.samplePoints = JSON.stringify(drawingForm.value.samplePointsArray)
    const res = await taskHttp.paintLinearEquation(drawingForm.value)
    console.log(res, 'addCurve')
    if (res.data.code == 200) {
        drawingForm.value.expression = res.data.data.expression
        drawingForm.value.intercept = res.data.data.intercept
        drawingForm.value.rsquared = res.data.data.rsquared
        drawingForm.value.slope = res.data.data.slope
        drawingForm.value.pointsArray.forEach(item => {
            item.yAxisValue = (item.multiplyValue * drawingForm.value.slope + drawingForm.value.intercept).toFixed(3)
        })
        chartDataList.value = drawingForm.value.pointsArray
        console.log(chartDataList.value, 'chartDataList.value')
    }
}
const handleResult = () => {
    let concentrationSum = 0
    drawingForm.value.samplePointsArray.forEach(item => {
        item.minusValue = (item.a220 - 2 * item.a275).toFixed(3)
        item.emptyValue = (item.minusValue - drawingForm.value.backtestingblankAresult).toFixed(3)
        item.testValue = ((item.emptyValue - drawingForm.value.intercept) / drawingForm.value.slope).toFixed(3)
        item.concentrationValue = (item.testValue / item.sampleVolume).toFixed(3)
        concentrationSum = Number(concentrationSum) + Number(item.concentrationValue)
    })
    drawingForm.value.concentrationAverage = (concentrationSum / drawingForm.value.samplePointsArray.length).toFixed(3)
}

const linearEquationConfirm = () => {
    drawingForm.value.points = JSON.stringify(drawingForm.value.pointsArray)
    drawingForm.value.samplePoints = JSON.stringify(drawingForm.value.samplePointsArray)
    emits('linearEquationFn', drawingForm.value)
}
const instruments = ref([])
const methodNames = ref([])
const units = ref([
    { valueName: 'μg/mL' },
    { valueName: 'mg/L' }
])
const detailData = async () => {
    const res = await taskHttp.queryTaskDetailById({ id: 3280 })
    instruments.value = JSON.parse(res.data.data.instruments)
    methodNames.value = JSON.parse(res.data.data.methodNames)
    console.log(methodNames.value, instruments.value)
}
watch(
    () => drawingForm.value.solutionConcent,
    (val) => {
        drawingForm.value.blankAresult = (drawingForm.value.blankA220 - 2 * drawingForm.value.blankA275).toFixed(3)
        drawingForm.value.pointsArray.forEach(item => {
            item.multiplyValue = (item.sampleVolume * drawingForm.value.solutionConcent).toFixed(3)
            item.minusValue = (item.a220 - 2 * item.a275).toFixed(3)
            item.emptyValue = (item.minusValue - drawingForm.value.blankAresult).toFixed(3)
        })
    },
    { deep: true }
)
watch(
    () => drawingForm.value.blankA220,
    (val) => {
        drawingForm.value.blankAresult = (drawingForm.value.blankA220 - 2 * drawingForm.value.blankA275).toFixed(3)
    },
    { deep: true }
)
watch(
    () => drawingForm.value.blankA275,
    (val) => {
        drawingForm.value.blankAresult = (drawingForm.value.blankA220 - 2 * drawingForm.value.blankA275).toFixed(3)
    },
    { deep: true }
)
watch(
    () => drawingForm.value.backtestingblankA220,
    (val) => {
        drawingForm.value.backtestingblankAresult = (drawingForm.value.backtestingblankA220 - 2 * drawingForm.value.backtestingblankA275).toFixed(3)
        drawingForm.value.pointsArray.forEach(item => {
            item.multiplyValue = (item.sampleVolume * drawingForm.value.solutionConcent).toFixed(3)
            item.minusValue = (item.a220 - 2 * item.a275).toFixed(3)
            item.emptyValue = (item.minusValue - drawingForm.value.backtestingblankAresult).toFixed(3)
        })
    },
    { deep: true }
)
watch(
    () => drawingForm.value.backtestingblankA275,
    (val) => {
        drawingForm.value.backtestingblankAresult = (drawingForm.value.backtestingblankA220 - 2 * drawingForm.value.backtestingblankA275).toFixed(3)
        drawingForm.value.pointsArray.forEach(item => {
            item.multiplyValue = (item.sampleVolume * drawingForm.value.solutionConcent).toFixed(3)
            item.minusValue = (item.a220 - 2 * item.a275).toFixed(3)
            item.emptyValue = (item.minusValue - drawingForm.value.blankbacktestingblankAresultAresult).toFixed(3)
        })
    },
    { deep: true }
)
watch(
    () => drawingForm.value.pointsArray,
    (val) => {
        val.forEach(item => {
            item.multiplyValue = (item.sampleVolume * drawingForm.value.solutionConcent).toFixed(3)
            item.minusValue = (item.a220 - 2 * item.a275).toFixed(3)
            item.emptyValue = (item.minusValue - drawingForm.value.blankAresult).toFixed(3)
        })
    },
    { deep: true }
)
watch(
    () => props.handleRowDetail,
    (val) => {
        console.log(val, '--====----')
        setTimeout(() => {
            initDate()
        }, 200)
    },
    { deep: true }
)
onMounted(() => {
    initDate()
    detailData()
})
defineExpose({
    linearEquationConfirm
})
</script>

<style lang="less" scoped>
.dialogContent {
    width: 760px;
    .dialogModel {
        margin-bottom: 20px;
        .modelTitle {
            font-size: 16px;
            line-height: 18px;
            height: 18px;
            padding-left: 10px;
            border-left: 4px solid #58be3f;
            margin-bottom: 10px;
            font-weight: 500;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            .operateIcon {
                margin-left: 10px;
                img {
                    width: 18px;
                    height: 18px;
                    margin: 0 2px;
                    cursor: pointer;
                }
            }
        }
    }
}

.operateIcon {
    display: flex;
    flex-direction: row;
    align-items: center;
}
.taskInfo {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    padding: 10px 0;
    p {
        margin-right: 60px;
        font-size: 14px;
    }
}
.templateInfo {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    .templateInfoItem {
        border: 1px solid #58be3f;
        background: #f7fcf6;
        border-radius: 8px;
        display: block;
        padding: 10px;
        width: 200px;
        margin-right: 20px;
        &.all {
            width: 100%;
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            flex-wrap: wrap;
            p {
                margin-right: 20px;
            }
        }
        .templateInfoItemHeader {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            .itemTitle {
                line-height: 2;
            }
            .itemChecked {
                margin-right: 10px;
            }
        }
        .templateInfoItemContent {
            p {
                line-height: 2;
            }
        }
    }
}
.loactionResult {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    .loactionResultValue {
        margin-right: 10px;
    }
    .loactionResultValueItem {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        margin-bottom: 4px;
    }
}
.curveEquation {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
}
.el-col-content {
    margin-bottom: 4px;
    position: relative;
    .averageValue {
        position: absolute;
        line-height: 32px;
        text-align: center;
        width: 100%;
    }
}
.el-col-content-th {
    font-size: 12px;
    text-align: center;
    line-height: 2;
}
.el-col-content-mr {
    margin-right: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
}
.calculationFormula {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    margin-bottom: 12px;
    .calculationFormulaContent {
        flex: 1;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        flex-wrap: wrap;
        .calculationFormulaContentItem {
            position: relative;
            .delelteItem {
                position: absolute;
                right: 1px;
                top: -3px;
                z-index: 1000;
                background: #f56c6c;
                border-radius: 4px;
                padding: 2px 2px 0px;
            }
        }
        p {
            width: 72px;
            text-align: right;
            margin-right: 26px;
        }
    }
}
.contentStyle {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
}
.success {
    color: #58be3f;
}
.danger {
    color: #f56c6c;
}
.warning {
    color: #e6a23c;
}
.nomarl {
    color: #666;
}
</style>